package com.sunrise.visual.frame.common
{
	import mx.controls.Alert;
	
	public class LineUtil
	{
		public var config:Object;
		public var data:Array;
		
		public function LineUtil(data:Array,config:Object)
		{
			this.data = data;
			this.config = config;
		}
		
		private function getXML():XML{
			var xml:XML = <anychart>
							<margin all="0" left={this.config.marginLeft || "0"} right={this.config.marginRight || "0"}/>
							<settings>
								<animation enabled="True" />
							</settings>
							<charts>
								<chart plot_type="CategorizedVertical">
									<data_plot_settings default_series_type="Bar">
										<line_series>
											<marker_settings enabled="True">
												<marker type={this.config.makerType || "None"} />
												<states>
													<hover>
														<marker type="Diamond" />
													</hover>
												</states>
											</marker_settings>
  											<label_settings enabled={config.labelFormat?"true":"false"}>
																	 <background enabled="false"/>
<font family="Microsoft Yahei" color="white" size="12" bold="false"/>
																	 <format>{config.labelFormat||"{%YValue}{numDecimals:0}%"}</format>
																	 <effects>
																	   <drop_shadow enabled="true" opacity="1"/>
																	 </effects>
																   </label_settings>
											<tooltip_settings enabled="True">
<font family="Microsoft Yahei" bold="false" size="12" />
												<format>{config.tooltipFormat || "时间:{%Name}{numDecimals:0}点\n{%SeriesName}:{%YValue}{numDecimals:2}"}</format>
											</tooltip_settings>
										</line_series>
									</data_plot_settings>
									<chart_settings>
										<chart_background enabled="false">
										      <inside_margin left="5" top="0" right="0" bottom="0"/>
										</chart_background>
										<data_plot_background enabled="false" />
										<data_plot_background enabled="false" />
										<title enabled={this.config.titleEnabled || "false"}>
											<text>{this.config.title || ''}</text>
<font family="Microsoft Yahei" bold="True" size="16" color="white" />
										</title>
										<controls>
											<label position="Fixed" anchor="RightTop" inside_dataplot={this.config.labelInsideDataplot || "true"} enabled={this.config.controlsLabelEnabled || "false"}>
<font family="Microsoft Yahei" bold="False" size="12" color="white" />
												<text>{this.config.controlsLabelText || "单位：亿千瓦时"}</text>
											</label>
										</controls>
										<axes>
											<x_axis>
												<line color="white" />
												<major_tickmark color="white" />
												<title enabled="false" />
												<labels rotation={this.config.format_rotation || "0"}>
<font family="Microsoft Yahei" bold="false" size="12" color="white" />
												</labels>
												<major_grid enabled="false" />
												<minor_grid enabled="false" />
											</x_axis>
											<y_axis>
											<scale  minimum = {this.config.minimum || "auto"} maximum = {this.config.maximum || "auto"} maximum_offset={this.config.maximumOffset||"0.1"}/>
			
												<line color="white" />
												<major_tickmark color="white" />
												<title enabled="false" />
												<labels>
<font family="Microsoft Yahei" bold="false" size="12" color="white" />
													<format>{"{%Value}{numDecimals:"}{this.config.format_Y1data || "2"}{"}"}</format>
												</labels>
												<major_grid enabled="false" />
												<minor_grid enabled="false" />
											</y_axis>
										</axes>
										<legend enabled={this.config.legendEnabled||"true"} ignore_auto_item="true" align="center" position={this.config.legendPosition || "bottom"} rows_padding="1">
<font family="Microsoft Yahei" bold="False" size="12" color="white">
											</font>
											<background enabled="false" />
											<title enabled="false" />
											<items>
												<item source="series" />
											</items>
											<icon series_type="Line">
												<marker enabled={this.config.iconMarkerEnabled || "False"} />
											</icon>
										</legend>
									</chart_settings>
									<data>
					
									</data>
								</chart>
							</charts>
						</anychart>;
			return xml;
		}
		
		
		public function parseXML():XML {
			var wdbm:String=this.config.wdbm;
			var zbbm:Array=this.config.zbbm;
			var zbmc:Array=this.config.zbmc;
			var xmlStr:String="";
			var seriesColor:Array = this.config.seriesColor || ['#00DFF3','#95A600'];
			var lineXml:XML =this.getXML();
			//lineXml.charts[0].chart[0].data[0]="";
			for(var i:int=0;i<zbbm.length;i++){
				xmlStr='<series name="'+zbmc[i]+'" type="' + (this.config.seriesType || "Spline") + '" color="'+seriesColor[i]+'">'; 
				for(var j:int=0;j<this.data.length;j++){
					xmlStr+='<point name="'+this.data[j][wdbm]+'" y="'+this.data[j][zbbm[i]]+'"/>';
				}
				xmlStr+='</series>';
				lineXml.charts[0].chart[0].data[0].appendChild(new XML(xmlStr));
			}
			//Alert.show(lineXml.toString());
			return   lineXml;
		}
	}
}